package org.example.threadlocaltest.demos.configure;

import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfigure {

    //从配置文件中读取 spring.redis.password 字段的值
    @Value("${spring.redis.password}")
    private String password;

    //    spring.redis.host=8.140.254.35
    @Value("${spring.redis.host}")
    private String host;

    //    spring.redis.port=6379
    @Value("${spring.redis.port}")
    private String port;


    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://" + host + ":" + port).setPassword(password);
        //设置序列化方式
        config.setCodec(new org.redisson.client.codec.StringCodec());
        return org.redisson.Redisson.create(config);
    }

}
